package routers

import (
	beego "github.com/beego/beego/v2/server/web"
	"go-cmdb/controllers"
	"go-cmdb/controllers/admin"
	"go-cmdb/controllers/home"
)

func init() {

	var (
		//后端
		adminNs = beego.NewNamespace("admin",
			beego.NSAutoRouter(admin.NewIndexController()),
			beego.NSAutoRouter(admin.NewLoginController()),
			beego.NSAutoRouter(admin.NewUserController()),
			beego.NSAutoRouter(admin.NewServerInfoController()),
			beego.NSAutoRouter(admin.NewBiController()),
			beego.NSAutoRouter(admin.NewExcelController()),
			beego.NSAutoRouter(admin.NewSettingController()),
			beego.NSAutoRouter(admin.NewRoleController()),
			beego.NSAutoRouter(admin.NewMenuController()),
			beego.NSAutoRouter(admin.NewMonitorController()),
			beego.NSAutoRouter(admin.NewFormController()),
			beego.NSAutoRouter(admin.NewWebSiteController()),
			beego.NSAutoRouter(admin.NewAgentController()),
		)

		//前端
		homeNs = beego.NewNamespace("home",
			beego.NSAutoRouter(home.NewDemoController()),
			beego.NSAutoRouter(home.NewIndexController()),
		)
	)
	//特殊定义(短路由)
	beego.Router("/bi/dash/?:tmpl:string/?:code:string", admin.NewBiController(), "get:Dash")
	beego.Router("/website/site/?:tmpl:string/?:code:string", admin.NewWebSiteController(), "get:Site")
	beego.Router("/form/?:uuid:string", admin.NewFormController(), "get:Preview")
	beego.Router("/", home.NewIndexController(), "get:Index")

	//控制器-(前端+后端)
	beego.AddNamespace(adminNs, homeNs)

	//捕捉异常
	beego.BConfig.RecoverPanic = true
	//控制器-错误整体处理
	beego.ErrorController(controllers.NewErrorController())

	beego.SetStaticPath("/static", "static")
	beego.SetViewsPath("views")

}
